import { tableForm } from '/@/libs/vxeUse';
import { h, } from "vue";
import {ElMessageBox} from 'element-plus'
export const formsUp = (data,callback,queryForm) => {
  let arr = [
    {
    label: "发货单号",
    key: "billNo",
    type: 'input',
    attrs:{
      disabled:true
    }
  },
 

  {
    label: "采购订单号",
    key: "purchaseOrderNo",
    type: 'select',
    optionList:data.listPur,
    optionValue: 'billNo',
    optionLabel: 'billNo',
    attrs:{
      onChange:(e)=>{
        if(data.tableData.length){
          ElMessageBox.confirm(
            '切换会清除数据 确定切换吗?',
            'Warning',
            {
              confirmButtonText: '确定',
              cancelButtonText: '关闭',
              type: 'warning',
            }
          )
            .then(() => {
              let id=data.listPur.find(item=>item.billNo==e).id
              callback(id)      
            }).catch(err=>{
              queryForm.purchaseOrderNo=queryForm.oldVz
            })
        }
        else{
          let id=data.listPur.find(item=>item.billNo==e).id
          callback(id)
        }
      },
      onVisibleChange:(e)=>{
        if(e){
          queryForm.oldVz=queryForm.purchaseOrderNo
        }
      }
    }
  },
  {
    label: "发货日期",
    key: "billDate",
    type: 'date',
  },
  {
    label: "运输方式",
    key: "transportMode",
    type: 'select',
    optionList:data.outList,
    optionValue: 'itemValue',
    optionLabel: 'itemName',
  },
  {
    label: "备注:",
    key: "remark",
    type: "input",
    attrs: {
      type: "textarea",
    },
  },
]

  return arr
}

export const tableDown = (data) => {
  let arr = [
    { type: 'checkbox', width: 50 },
    { type: 'seq', width: 150,title:'序号', className: "vxe-table-disabled" },
    {
      field: 'materialNo', title: '物料编号', className: "vxe-table-disabled"
    },
    {
      field: 'materialName', title: '物料名称', className: "vxe-table-disabled"
    },
    {
      field: 'materialLot', title: '批号', className: "vxe-table-disabled"
    },
    {
      field: 'productPlace', title: '产地', className: "vxe-table-disabled"
    },
    {
      field: 'qty', title: '订单数量', className: "vxe-table-disabled"
    },
    {
      field: 'unit', title: '单位', className: "vxe-table-disabled"
    },
    {
      field: 'deliveryDate', title: '交期', className: "vxe-table-disabled"
    },

    {
      field: 'purchaseQty', title: '发货数量', editRender: {
        ...tableForm.input({})
      },
    },
   
    {
      field: 'remark', title: '备注', editRender: {
        ...tableForm.input({})
      },
    },
   
   
  ];
  return arr
}